package com.ifonly.activerecord.helpers;

import com.ifonly.activerecord.Model;
import com.ifonly.activerecord.annotation.Table;
import com.ifonly.utils.StringUtils;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-18 14:38
 * @since JDK 1.6
 */
public class TableMapHelper {

    /**
     * parse table name from model class
     *
     * @param clazz model class
     * @return table table
     */
    public static String tableName(Class<? extends Model> clazz) {
        Table table = clazz.getAnnotation(Table.class);
        String tableName;
        if (table != null) {
            tableName = table.name();
        } else {
            String classSimpleName = clazz.getSimpleName();
            tableName = StringUtils.firstCharToLowerCase(classSimpleName);
        }
        return tableName;
    }

}
